// 运行时配置

import { BookOutlined, LinkOutlined } from "@ant-design/icons";
import { history,Link } from "@umijs/max";
import React from "react";

// 约定一个地方生产和消费初始化数据。
export async function getInitialState() {

  if (
    history.location.pathname !== "/login" &&
    history.location.pathname !== "/404"
  ) {
    try {
     
    } catch (error) {}
  }
  return { name: '@umijs/max' };
}

export const layout = () => {
  return {
    //菜单显示模式
    layout: "mix",
    navTheme: "light",
    headerHeight: 56,
    token: {
      layoutBgColor: "#fff",
      header: {
        headerBgColor: "#fff",
      },
      sider: {
        menuBackgroundColor: "#fff",
      },
      pageContainer: {
        pageContainerBgColor: "#fff",
        pageContainerContentMargin: "#fff",
      },
    },
    // siderWidth: 208,
    //发生错误后的回调（可做一些错误日志上报，打点等）。c
    onError: (err: any) => {
     
    },
    // 菜单
    postMenuData: (menuData: any) => {
      // 因为目前登录后无法刷新菜单导入权限不会变动 这样来处理可以有效刷新菜单的
      return menuData;
    },
    // 自定义PageContainer breadcrumb 渲染样式
    itemRender: (route: any, params: any, routes: any, paths: any) => {
      // 查找路由配置里面对于路由是否
   
      let props: any = {};
      // 如果配置 component 表示有页面可以跳转
      props.name = route.breadcrumbName;

      return props.to
        ? React.createElement(
            Link,
            {
              to: props.to,
            },
            props.name
          )
        : React.createElement("span", {}, props.name);
    },
   
    // //自定义页脚
    // footerRender: (BasicLayoutProps: any) => {
    //   return React.createElement(DefaultFooter, {
    //     copyright: ' 2021 出品',
    //     links: [
    //       // { key: 'test', title: 'layout', href: 'www.alipay.com' },
    //       // { key: 'test2', title: 'layout2', href: 'www.alipay.com' },
    //     ],
    //   });
    // },
    footerRender: false,
    //配置开发模式下文档地址
    links:
      process.env.UMI_ENV === "local"
        ? [
            React.createElement(
              Link,
              {
                to: "/~docs",
                target: "_blank",
              },
              [
                React.createElement(BookOutlined, {
                  key: "icon",
                }),
                React.createElement(
                  "span",
                  {
                    key: "text",
                  },
                  "业务组件文档"
                ),
              ]
            ),
            React.createElement(
              Link,
              {
                to: "/umi/plugin/openapi",
                target: "_blank",
              },
              [
                React.createElement(LinkOutlined, {
                  key: "icon",
                }),
                React.createElement(
                  "span",
                  {
                    key: "text",
                  },
                  "openAPI 文档"
                ),
              ]
            ),
          ]
        : [],

    layoutBgImgList: [
      {
        src: "https://img.alicdn.com/imgextra/i2/O1CN01O4etvp1DvpFLKfuWq_!!6000000000279-2-tps-609-606.png",
        left: 85,
        bottom: 100,
        height: "303px",
      },
      {
        src: "https://img.alicdn.com/imgextra/i2/O1CN01O4etvp1DvpFLKfuWq_!!6000000000279-2-tps-609-606.png",
        bottom: -68,
        right: -45,
        height: "303px",
      },
      {
        src: "https://img.alicdn.com/imgextra/i3/O1CN018NxReL1shX85Yz6Cx_!!6000000005798-2-tps-884-496.png",
        bottom: 0,
        left: 0,
        width: "331px",
      },
    ],
  };
};
